using Godot;
using System;

public partial class Emeny : Sprite2D
{
	[Export]
	public CollisionShape2D[] environmentArea { get; set; }
	[Export]
	public Sprite2D emenyPhoto { get; set; }
	[Export]
	public Label HPText { get; set; }
	public EmenyCard[] emenyCards = new EmenyCard[5];
	public int HP = 4000;
	public int staging = 0;
	private Godot.Collections.Dictionary data;


	public override void _Ready()
	{
		using FileAccess file = FileAccess.Open("res://data.json", FileAccess.ModeFlags.Read);
		string jsonText = file.GetAsText();
		Json json = new Json();
		Error error = json.Parse(jsonText);
		data = json.Data.AsGodotDictionary();
		getCard(0, 12);
	}
	void nextEnergySignalHander(int stages)
	{
		this.staging = stages;
		if (stages == 1)
		{
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/emeny1.png");
			HP = 8000;
			HPText.Text = "HP:" + HP;
			getCard(1, 13);
			getCard(3, 13);
		}
		else if (stages == 2)
		{
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/fakerWoman.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 15);
			getCard(1, 16);
			getCard(2, 17);
			getCard(3, 18);
			getCard(4, 14);
		}
		else if (stages == 3)
		{
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 19);
		}else if (stages == 4)
		{
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/emeny3.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 20);
<<<<<<< HEAD
			getCard(1, 20);
			getCard(2, 20);
			getCard(3, 20);
			getCard(4, 20);
		}else if (stages == 5)
		{
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/fakerwn.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 23);
			getCard(1, 25);
			getCard(2, 27);
		}else if (stages == 6)
		{
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 24);
			getCard(1, 26);
			getCard(2, 28);
		}else if (stages == 7)
		{
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/emeny4.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 21);
			getCard(1, 22);
		}else if (stages == 8)
		{
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/bossFace.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 30);
=======
			getCard(0, 20);
			getCard(0, 20);
			getCard(0, 20);
			getCard(0, 20);
		}else if (stages == 5)
		{
			//三张光能使者
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/emeny2.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 20);
			getCard(0, 20);
			getCard(0, 20);
		}else if (stages == 6)
		{
			//三张超级光能使者
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/emeny2.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 20);
			getCard(0, 20);
			getCard(0, 20);
		}else if (stages == 7)
		{
			//光能大贤者
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/emeny2.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 20);
		}else if (stages == 8)
		{
			//混沌魔法师  六重魔法师
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/emeny2.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 20);
			getCard(0, 20);
		}else if (stages == 9)
		{
			//最终boss
			emenyPhoto.Texture = GD.Load<Texture2D>("res://photo/boss/emeny2.png");
			HP = 12000;
			HPText.Text = "HP:" + HP;
			getCard(0, 20);
>>>>>>> 5e5a1b5c372f73f20a8064c93772fa480d326604
		}else{
			
		}

	}
	void getCard(int locations, int num)
	{
		var jsonData = data["card"].AsGodotArray();
		var tmp = jsonData[num].AsGodotDictionary();
		emenyCards[locations] = new EmenyCard()
		{
			id = Guid.NewGuid().ToString(),
			location = locations + 1,
			name = tmp["name"].AsString(),
			atk = tmp["atk"].AsInt32(),
			attribute = tmp["attribute"].AsString(),
			def = tmp["def"].AsInt32(),
			grade = tmp["grade"].AsInt32(),
			placePosition = environmentArea[locations].GlobalPosition
		};
		if (this.staging == 1)
		{
			emenyCards[locations].penetrate = true;
		}
		else if (this.staging == 2)
		{
			emenyCards[locations].kjysTag = true;
			emenyCards[locations].trueAtk=tmp["atk"].AsInt32();
			emenyCards[locations].trueDef=tmp["def"].AsInt32();
		}
		else if (this.staging == 3)
		{
			emenyCards[locations].kjysSumTag = true;
		}
		else if (this.staging == 4)
		{
			emenyCards[locations].sexyMagic = true;
		}
		else if (this.staging == 5)
		{

		}
		else if (this.staging == 6)
		{
			emenyCards[locations].superGnsz = true;
			emenyCards[locations].superFbsz = true;
			emenyCards[locations].superBtsz = true;
		}
		else if (this.staging == 7)
		{
			if (emenyCards[locations].name == "混沌魔法师")
			{
				emenyCards[locations].mixMagic = true;
			}
			else
			{
				emenyCards[locations].sixMagicTag = true;
			}
		}
		AddChild(emenyCards[locations]);
	}
}
